/*------------------------------------------------------------------------------
--                                                                            --
--       This software is confidential and proprietary and may be used        --
--        only as expressly authorized by a licensing agreement from          --
--                                                                            --
--                            Hantro Products Oy.                             --
--                                                                            --
--      In the event of publication, the following notice is applicable:      --
--                                                                            --
--                   (C) COPYRIGHT 2003 HANTRO PRODUCTS OY                    --
--                            ALL RIGHTS RESERVED                             --
--                                                                            --
--          The entire notice above must be reproduced on all copies.         --
--                                                                            --
--------------------------------------------------------------------------------
--
--  Project  : 1200s
--
--  Abstract : Encoder wrapper layer
--
--------------------------------------------------------------------------------
--
--  Version control information, please leave untouched.
--
--  $RCSfile: ewl.h,v $
--  $Author: vira $
--  $Date: 2007/06/29 15:25:40 $
--  $Revision: 1.1 $
--  $Name: DirectShow_Rel_HiSilicon_0_1 $
--
------------------------------------------------------------------------------*/

#ifndef __EWL_H__
#define __EWL_H__

#include "basetype.h"

#ifdef __cplusplus
extern "C" { /* allow C++ to use these headers */
#endif /* __cplusplus */


#undef PTRACE   /* undef it, just in case */
#if defined(TRACE_EWL)
#   define PTRACE(fmt, args...) printf(__FILE__ ":%d: " fmt, __LINE__ , ## args)
#elif defined(__GNUC__)
#   define PTRACE(fmt, args...) /* no trace */
#else
#   define PTRACE()
#endif

#define ENC_MEM_SIZE          1<<20               // reserve 1 MB for linear allocation pool

#define EWL_NOK      -1
#define EWL_OK        0
#define EWL_TIMEOUT   1

/*
enum ewl_ret
{
    EWL_NOK = -1,
    EWL_OK,
    EWL_TIMEOUT,
}
*/

/*****************************************************
 * Function: EWL_Init
 * Description: initialize encoder
 * Calls: 
 * Called by: encode algrithm
 * Table Access: list the table you will use. 
 * Table Update: list the table which you will update.
 * Input:  None
 * Output: NONE
 * Return: EWL_OK if success, else EWL_NOK
 * Others: NONE
 ****************************************************/
i32 EWL_Init(void);

/*****************************************************
 * Function: EWL_Release
 * Description: Release encoder
 * Calls: 
 * Called by: encode algrithm
 * Table Access: list the table you will use. 
 * Table Update: list the table which you will update.
 * Input:  None
 * Output: NONE
 * Return: EWL_OK
 * Others: NONE
 ****************************************************/ 
i32 EWL_Release(void);

/*****************************************************
 * Function: EWL_WriteReg
 * Description: Write regiter
 * Calls: 
 * Called by: encode algrithm
 * Table Access: list the table you will use. 
 * Table Update: list the table which you will update.
 * Input:  offset[in]:  offset of the regiter
 *         val[in]:     value to set
 * Output: NONE
 * Return: NONE
 * Others: NONE
 ****************************************************/ 
void EWL_WriteReg( u32 offset, u32 val );

/*****************************************************
 * Function: EWL_ReadReg
 * Description: Read regiter
 * Calls: 
 * Called by: encode algrithm
 * Table Access: list the table you will use. 
 * Table Update: list the table which you will update.
 * Input:  offset[in]:  offset of the regiter
 *        
 * Output: NONE
 * Return: value of the register	
 * Others: NONE
 ****************************************************/
u32 EWL_ReadReg( u32 offset );

/*****************************************************
 * Function: EWL_MallocBuffer
 * Description: malloc reserved buffer from high address
 * Calls: 
 * Called by: encode DMO, JPEG encoder
 * Table Access: list the table you will use. 
 * Table Update: list the table which you will update.
 * Input:  size[in]:         size of buffer to alloc, count in byte
 *        
 * Output: pPhyAddr[out]:    Pointer to the address of buffer malloced 
 * Return: address of buffer malloced	
 * Others: NONE
 ****************************************************/ 
u32* EWL_MallocBuffer( u32 size, u32** pPhyAddr);

/*****************************************************
 * Function: EWL_FreeBuffer
 * Description: free reserved buffer malloced by EWL_MallocBuffer
 * Calls: 
 * Called by: encode DMO, JPEG encoder
 * Table Access: list the table you will use. 
 * Table Update: list the table which you will update.
 * Input: pVirt[in]:  Pointer to address of buffer to free
 *        
 * Output: NONE
 * Return: NONE	
 * Others: NONE
 ****************************************************/ 
void EWL_FreeBuffer( u32* pVirt );

/*****************************************************
 * Function: EWL_MallocLinear
 * Description: malloc reserved buffer from low address
 * Calls: 
 * Called by: encoder algrithm
 * Table Access: list the table you will use. 
 * Table Update: list the table which you will update.
 * Input: size[in]:  size of buffer to alloc, count in byte
 *        
 * Output: None
 * Return: address of buffer malloced	
 * Others: NONE
 ****************************************************/
u32* EWL_MallocLinear( u32 size );

/*****************************************************
 * Function: EWL_FreeLinear
 * Description: free reserved buffer malloced by EWL_MallocLinear
 * Calls: 
 * Called by: encode algrithm
 * Table Access: list the table you will use. 
 * Table Update: list the table which you will update.
 * Input: pVirt[in]:  Pointer to address of buffer to free
 *        
 * Output: NONE
 * Return: NONE	
 * Others: NONE
 ****************************************************/ 
void EWL_FreeLinear( u32* pVirt );

/*****************************************************
 * Function: EWL_Virt2Bus
 * Description: convert virtual address to phisical address
 * Calls: 
 * Called by: encode algrithm
 * Table Access: list the table you will use. 
 * Table Update: list the table which you will update.
 * Input: pVirt[in]:  Pointer to address of buffer to convert
 *        
 * Output: NONE
 * Return: NONE	
 * Others: NONE
 ****************************************************/
u32 EWL_Virt2Bus( u32* pVirt );

i32 EWL_PostHwRdy(void);

/*****************************************************
 * Function: EWL_Virt2Bus
 * Description: convert virtual address to phisical address
 * Calls: 
 * Called by: encode algrithm
 * Table Access: list the table you will use. 
 * Table Update: list the table which you will update.
 * Input: pVirt[in]:  Pointer to address of buffer to convert
 *        
 * Output: NONE
 * Return: NONE	
 * Others: NONE
 ****************************************************/
i32 EWL_WaitHwRdy(void);

/*****************************************************
 * Function: EWL_ResetHwRdy
 * Description: Reset the wating status
 * Calls: 
 * Called by: encode algrithm
 * Table Access: list the table you will use. 
 * Table Update: list the table which you will update.
 * Input:  None
 *        
 * Output: NONE
 * Return: EWL_OK if success, else return EWL_NOK
 * Others: NONE
 ****************************************************/
i32 EWL_ResetHwRdy(void);

#ifdef __cplusplus
} /* allow C++ to use these headers */
#endif /* __cplusplus */


#endif /*__EWL_H__*/
